﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using NCRGEA.AAL;
using NCRGEA.Members;

namespace NCRGEA.UtilityForms
{
    public partial class frmDisplayData : Form
    {
        #region Class Variables

        DataTable displayData = new DataTable();

        #endregion

        #region Data Manipulation
        //
        #endregion

        public frmDisplayData()
        {
            InitializeComponent();
        }

        public frmDisplayData(string query, SqlParameter[] param) : this()
        {
            if (param != null)
                displayData = DAL.ExecuteQuery(query, param);
            else
                displayData = DAL.ExecuteQuery(query);
            
            dcDataDisplay.DataSource = displayData;
            
            Logger.Log("Number of total rows: " + displayData.Rows.Count.ToString());
        }

        private void dcDataDisplay_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dcDataDisplay.SelectedCells.Count > 0)
            {
                int memberID = (int)((DataTable)dcDataDisplay.DataSource).Rows[e.RowIndex]["MemberID"];
                
                Members.frmViewMember fViewMember = new Members.frmViewMember(memberID);
                
                NCRGEA.frmMain temp = (frmMain)this.MdiParent;

                if (temp != null)
                    temp.LaunchForm(fViewMember);
            }
        }

        private void btnCSV_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Reports.frmDynamicReport a = new Reports.frmDynamicReport((DataTable)dcDataDisplay.DataSource);
            a.Show();
        }
    }
}
